package com.drought.rained.presenter;

import com.drought.rained.business.CustomConsumerLJ;
import com.drought.rained.business.ParamsFactoryLJ;
import com.drought.rained.cache.UserInfoLJ;
import com.drought.rained.mvpview.PersonalAuthMvpViewLJ;
import com.drought.rained.response.AuthInfoResponseLJ;
import com.drought.rained.response.BlankResponseLJ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class PersonalAuthPresenterLJ extends BasePresenterLJ {
    private PersonalAuthMvpViewLJ mvpView;

    public PersonalAuthPresenterLJ(PersonalAuthMvpViewLJ mvpView) {
        this.mvpView = mvpView;
    }

    public void getAuthInfo() {
        Map<String, Object> map = new HashMap<>();
        map.put("userUuid", UserInfoLJ.getShowUuid());
        List<String> pageCodes = new ArrayList<>();
        pageCodes.add("personage_info_code");
        map.put("pageCodes", pageCodes);
        toSubScribe(req.getAuthInfoData(UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(map)), new CustomConsumerLJ<AuthInfoResponseLJ>() {
            @Override
            public void call(AuthInfoResponseLJ response) {
                mvpView.onGetDataNext(response);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

    public void saveAuthInfo(Map<String, Object> map) {
        map.put("userUuid", UserInfoLJ.getSaveUuid());
        map.put("authPageCode", "personage_info_code");
        if (UserInfoLJ.isUserInformationWrong())
            map.put("isInformationWrong", 1);
        toSubScribe(req.savePersonalAuth(UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(map)), new CustomConsumerLJ<BlankResponseLJ>() {
            @Override
            public void call(BlankResponseLJ response) {
                mvpView.onGetDataNext(response);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
